plinstrument:
{
calc:"
// LED Wash 1812Z RGBW (based on PEGASYS EAGLE)

#include	colorconv
#include	hsv
#include	ledref
#include	strobe

// controls
cMod;
cDim; cSht; cFnc; cFns; cR; cG; cB; cW; cZom; cRst;

// parameters
pMod;

// constants
kDia = 0.118;
kWid = 0.194;
kHi = 0.194;
kZBack = 0.136;
kZFront = -0.152;

kSource = LEDRefConv(18 * 12, kDia, kLEDRefWatt_RGBW, kLEDRefDia_RGBW, kLEDRefSrc_RGBW);
kWhite = kLEDRefWhite_RGBW;


// protocol parameters
LIGHT;
SHAPE;
CTLS;

PRM=1;
CTL;


// dimmer

gDimmer;


DimmerTime#
(
	(pMod == 0)?
	(
		gDimmer = 1;
	)
	:
	(
		gDimmer = cDim / 255;
	);
);


// shutter (of Flat Par Tri18)

kStrobeMin = 1;			// [Hz]
kStrobeMax = 25;		// [Hz]
kStrobeDur = 1 / 30;	// [s] (?)

gShutter;
gStrobe[0];


ShutterTime#
(
	(pMod == 0)?
	(
		gShutter = 1;
	)
	:
	(
		(cSht < 2)?	// open (?)
		(
			gShutter = 1;
		)
		:			// strobe
		(
			ss = ParamSqr(kStrobeMin, kStrobeMax, 2, 255, cSht);
			StrobeProgress(gStrobe, $0 * ss, kStrobeDur * ss);
			gShutter = gStrobe.ef;
		);
	);
);


// color
kColorSpeedMax = 167 / 60;		// [1/s] (?) (of Alpha Spot HPE 300)
kColorSpeedMin = 0.2 / 60;		// [1/s] (?) (of Alpha Spot HPE 300)

gColor;		// rgbw
gColorPh;


ColorTime#
(
	(pMod == 0)?
	(
		gColor = Vec(cR / 255, cG / 255, cB / 255, cW / 255);
	)
	:
	(
		(cFnc < 51)?
		(
			gColor = Vec(cR / 255, cG / 255, cB / 255, cW / 255);
		)
		:(cFnc < 101)?	// fixed (hue?)
		(
			h = floor(12 * cFns / 256) / 12;	// 12 colors (?)
			gColor = RGBfromHSV(h, 1, 1);
		)
		:(cFnc < 151)?	// jump (hue?)
		(
			cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
			gColorPh = Cycle(gColorPh + $0 * cs);
			h = floor(12 * gColorPh) / 12;	// 12 colors (?)
			gColor = RGBfromHSV(h, 1, 1);
		)
		:(cFnc < 201)?	// fade (hue?)
		(
			cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
			gColorPh = Cycle(gColorPh + $0 * cs);
			h = gColorPh;
			gColor = RGBfromHSV(h, 1, 1);
		)
		:(cFnc < 251)?	// pulse (hue?)
		(
			cs = ParamSqr(kColorSpeedMin, kColorSpeedMax, 0, 255, cFns);
			gColorPh = Cycle(gColorPh + $0 * cs * 0.5);
			h = 2 * ((gColorPh < 0.5)? gColorPh : (1 - gColorPh));
			gColor = RGBfromHSV(h, 1, 1);
		)
		:	// sound (no support)
		(
			gColor = Vec(1, 1, 1, 1);
		);
	);
);


// zoom

kFocusSpeed = 1 / 1.5;				// [1/s] (of XL 700)
kZoomSpeed = kFocusSpeed;

gZoom;

ZoomTime#
(
	gZoom += LimitChange($0, cZom / 255 - gZoom, kZoomSpeed);
);


// protocol methods

UPDATE#
(
	DimmerTime($0);
	ShutterTime($0);
	ColorTime($0);
	ZoomTime($0);

	PRM?
	(
		// shape
		hw = kWid * 0.5;
		SHAPE = Box(-hw, hw, -hw, hw, kZBack, kZFront);
			
		cMod = pMod;
		CTLS = 1;

		l = LIGHT[0];
		l.pos[2] = kZFront;
		l.dia = kDia;
		LIGHT[0] = l;
	);

//	(CTL | PRM)?
	(
		fa = ParamLin(60, 6, 0, 1, gZoom);	// (field angle?)
		cnt = ParamLin(2, 0, 0, 1, gZoom);
		spd = Spread(cnt, 0.1, fa);

		c = RGBfromRGBW(gColor, kWhite);

		// setup light
		l = LIGHT[0];
		l.color = VecScale(c, kSource * gDimmer * gShutter);
		l.cnt = cnt;
		l.spdh = spd;
		l.spdv = spd;
		LIGHT[0] = l;
	);

	PRM = CTL = 0;
);

";


chmap:
     cR cG cB cW                cZom cRst,
cDim cR cG cB cW cSht cFnc cFns cZom cRst;


ctl:
{
	controls:
	{
		type:mode;
		id:cMod;

		modes:
		{
			controls:
			{
				type:numeric;
				id:cR;
				name:R;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cG;
				name:G;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cB;
				name:B;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cW;
				name:W;
				max:255;
				ini:255;
			};
		},
		{
			controls:
			{
				type:numeric;
				id:cDim;
				name:Dimmer;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cR;
				name:R;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cG;
				name:G;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cB;
				name:B;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cW;
				name:W;
				max:255;
				ini:255;
			},
			{
				type:numeric;
				id:cSht;
				name:Strobe;
				max:255;
			},
			{
				type:numeric;
				id:cFnc;
				name:Function;
				max:255;
			},
			{
				type:numeric;
				id:cFns;
				name:Speed;
				max:255;
			};
		};
	},
	{
		type:numeric;
		id:cZom;
		name:Zoom;
		max:255;
	},
	{
		type:numeric;
		id:cRst;
		name:Reset;
		max:255;
	};
};


prm:
{
	controls:
	{
		type:selector;
		id:pMod;
		name:Mode;
		ini:0;
		items:
		{
			text:6 ch;
			value:0;
		},
		{
			text:10 ch;
			value:1;
		};
	};
};

};
